package com.prawn.ift_baseconfig.controller;

import com.alibaba.fastjson.JSONObject;
import com.prawn.ift_baseconfig.pojo.WarningConfig;
import com.prawn.ift_baseconfig.service.WarningConfigService;
import entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/10/25
 * @DESC： 预警阈值配置信息管理
 */
@Controller
public class WarningConfigController {

    @Autowired
    private WarningConfigService warningConfigService;

    /**
     * 添加预警阈值配置信息
     * @Param warningConfig
     * @return Result
     */
    @RequestMapping("/warning/config/add")
    @ResponseBody
    public Result add(WarningConfig warningConfig) {
        //初始化参数
        warningConfig.setId(UUID.randomUUID().toString().replaceAll("-",""));
        warningConfig.setCreateDate(new Date());
        warningConfig.setUpdateDate(new Date());
        return warningConfigService.addWarningConfig(warningConfig);
    }

    /**
     * 删除预警阈值配置信息
     * @Param id
     * @return Result
     */
    @RequestMapping("/warning/config/delete")
    @ResponseBody
    public Result delete(String id) {
        return warningConfigService.deleteWarningConfig(id);
    }

    /**
     * 批量删除预警阈值
     * @Param id
     * @return Result
     */
    @RequestMapping("/warning/config/batchDel")
    @ResponseBody
    public Result batchDel(@RequestBody String ids) {
        JSONObject jsonObject=(JSONObject) JSONObject.parse(ids);
        List<String> ids1 = jsonObject.getJSONArray("ids").toJavaList(String.class);

        return warningConfigService.batchDelByIds(ids1);
    }

    /**
     * 修改预警阈值配置信息
     * @Param warningConfig
     * @return Result
     */
    @RequestMapping("/warning/config/edit")
    @ResponseBody
    public Result edit(WarningConfig warningConfig) {
        warningConfig.setUpdateDate(new Date());
        return warningConfigService.editWarningConfig(warningConfig);
    }

    /**
     * 查询预警阈值配置信息
     * @return WarningConfig
     */
    @RequestMapping("/warning/config/{id}")
    @ResponseBody
    public WarningConfig get(@PathVariable String id) {
        return warningConfigService.getWarningConfigById(id);
    }

    /**
     * 查询预警阈值配置信息列表
     * @return Result
     */
    @RequestMapping("/warning/config/list")
    @ResponseBody
    public Result getList() {
        return warningConfigService.getWarningConfigList();
    }

    /**
     * 通过场景查询预警阈值配置信息列表
     * @return Result
     */
    @RequestMapping("/warning/config/list/{sceneId}")
    @ResponseBody
    public Result getList(@PathVariable String sceneId) {
        return warningConfigService.getWarningConfigListByScenery(sceneId);
    }

    /**
     * 通过场景和检查项查询预警阈值配置信息列表
     * @return Result
     */
    @RequestMapping("/warning/config/equipment/list")
    @ResponseBody
    public Result getListById(String sceneId,String checkItemId) {
        return warningConfigService.getWarningConfigListBySceneryAndChannel(sceneId,checkItemId);
    }

    /**
     * 分页查询预警阈值配置信息列表
     * @return Result
     */
    @RequestMapping("/warning/config/page")
    @ResponseBody
    public Result getPage(int page,int limit) {
        return warningConfigService.getWarningConfigPage(page,limit);
    }

}
